
<!DOCTYPE HTML>
<html lang="" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>单表操作 · GitBook</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        
        
        
    
    <link rel="stylesheet" href="../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-search/search.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="page.html" />
    
    
    <link rel="prev" href="crud.html" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="Type to search" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="../">
            
                <a href="../">
            
                    
                    介绍
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" >
            
                <span>
            
                    
                    快速开始
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.2.1" data-path="param.html">
            
                <a href="param.html">
            
                    
                    参数获取
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.2" data-path="crud.html">
            
                <a href="crud.html">
            
                    
                    增删改查
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="1.2.3" data-path="table.html">
            
                <a href="table.html">
            
                    
                    单表操作
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.4" data-path="page.html">
            
                <a href="page.html">
            
                    
                    分页查询
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.3" >
            
                <span>
            
                    
                    核心模块
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.3.1" data-path="../module/db.html">
            
                <a href="../module/db.html">
            
                    
                    db模块
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.2" data-path="../module/http.html">
            
                <a href="../module/http.html">
            
                    
                    http模块
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.3" data-path="../module/log.html">
            
                <a href="../module/log.html">
            
                    
                    log模块
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.4" data-path="../module/env.html">
            
                <a href="../module/env.html">
            
                    
                    env模块
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.4" >
            
                <span>
            
                    
                    特殊函数
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.4.1" data-path="../function/agg.html">
            
                <a href="../function/agg.html">
            
                    
                    聚合函数
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.2" data-path="../function/date.html">
            
                <a href="../function/date.html">
            
                    
                    日期函数
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.3" data-path="../function/string.html">
            
                <a href="../function/string.html">
            
                    
                    字符串函数
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.4" data-path="../function/array.html">
            
                <a href="../function/array.html">
            
                    
                    数组函数
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.5" data-path="../function/math.html">
            
                <a href="../function/math.html">
            
                    
                    数学函数
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.6" data-path="../function/other.html">
            
                <a href="../function/other.html">
            
                    
                    其他函数
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.5" >
            
                <span>
            
                    
                    对象方法
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.5.1" data-path="../object/object.html">
            
                <a href="../object/object.html">
            
                    
                    Object对象
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.2" data-path="../object/number.html">
            
                <a href="../object/number.html">
            
                    
                    Number对象
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.3" data-path="../object/list.html">
            
                <a href="../object/list.html">
            
                    
                    数组&集合
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.4" data-path="../object/date.html">
            
                <a href="../object/date.html">
            
                    
                    Date对象
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.5" data-path="../object/class.html">
            
                <a href="../object/class.html">
            
                    
                    Class对象
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.6" data-path="../object/pattern.html">
            
                <a href="../object/pattern.html">
            
                    
                    Patter对象
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.6" >
            
                <span>
            
                    
                    脚本语法
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.6.1" data-path="../syntax/keyword.html">
            
                <a href="../syntax/keyword.html">
            
                    
                    关键字
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.2" data-path="../syntax/type.html">
            
                <a href="../syntax/type.html">
            
                    
                    类型
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.3" data-path="../syntax/yunsuan.html">
            
                <a href="../syntax/yunsuan.html">
            
                    
                    运算符
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.4" data-path="../syntax/yiyuan.html">
            
                <a href="../syntax/yiyuan.html">
            
                    
                    运算符示例
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.5" data-path="../syntax/for.html">
            
                <a href="../syntax/for.html">
            
                    
                    for循环
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.6" data-path="../syntax/import.html">
            
                <a href="../syntax/import.html">
            
                    
                    导入
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.7" data-path="../syntax/async.html">
            
                <a href="../syntax/async.html">
            
                    
                    异步
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            Published with GitBook
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href=".." >单表操作</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <p>&#x64CD;&#x4F5C;&#x5165;&#x53E3;&#xFF1A;<code>db.table(&apos;table_name&apos;)</code></p>
<h4 id="logic">logic</h4>
<ul>
<li>&#x4F5C;&#x7528;:&#x8BBE;&#x7F6E;&#x672C;&#x67E5;&#x8BE2;&#x662F;&#x5E26;&#x6709;&#x903B;&#x8F91;&#x5220;&#x9664;&#x7684;,&#x5728;&#x6267;&#x884C;<code>delete</code>&#x65B9;&#x6CD5;&#x65F6;&#xFF0C;&#x4F1A;&#x8F6C;&#x6362;&#x4E3A;<code>update</code>&#x8BED;&#x53E5;&#xFF0C;&#x5728;&#x6267;&#x884C;<code>select</code>&#x76F8;&#x5173;&#x65B9;&#x6CD5;&#x65F6;&#xFF0C;&#x4F1A;&#x62FC;&#x63A5;<code>logic_field &lt;&gt; logic_value</code></li>
</ul>
<h4 id="withblank">withBlank</h4>
<ul>
<li>&#x4F5C;&#x7528;&#xFF1A;&#x8BBE;&#x7F6E;&#x540E;&#x7EED;&#x63D2;&#x5165;&#x6216;&#x4FEE;&#x6539;&#x65F6;&#xFF0C;&#x4E0D;&#x8FC7;&#x6EE4;&#x7A7A;&#x503C;&#x3002;</li>
</ul>
<h4 id="column">column</h4>
<ul>
<li>&#x5165;&#x53C2;&#xFF1A;<code>column</code>: <code>String</code> &#x5217;&#x540D;</li>
<li>&#x4F5C;&#x7528;&#xFF1A;&#x8BBE;&#x7F6E;&#x8981;&#x67E5;&#x8BE2;&#x5217;&#x7684;,<code>select</code>&#x8BED;&#x53E5;&#x4E2D;&#x6709;&#x6548;</li>
</ul>
<h4 id="column">column</h4>
<ul>
<li>&#x5165;&#x53C2;&#xFF1A;<code>column</code>: <code>String</code> &#x5217;&#x540D;</li>
<li>&#x5165;&#x53C2;&#xFF1A; <code>value</code> : <code>Object</code> &#x503C;</li>
<li>&#x4F5C;&#x7528;&#xFF1A;&#x8BBE;&#x7F6E;&#x8981;&#x64CD;&#x4F5C;&#x7684;&#x5217;&#x7684;&#x503C;,&#x975E;<code>select</code>&#x8BED;&#x53E5;&#x4E2D;&#x6709;&#x6548;</li>
</ul>
<h4 id="primary">primary</h4>
<ul>
<li>&#x5165;&#x53C2;&#xFF1A;<code>primary</code>: <code>String</code> &#x4E3B;&#x952E;</li>
<li>&#x5165;&#x53C2;&#xFF1A;<code>defaultValue</code>: <code>Object</code> &#x63D2;&#x5165;&#x65F6;&#x4F7F;&#x7528;&#x7684;&#x9ED8;&#x8BA4;&#x503C;&#xFF0C;&#x53EF;&#x7701;&#x7565;</li>
<li>&#x4F5C;&#x7528;&#xFF1A;&#x8BBE;&#x7F6E;&#x4E3B;&#x952E;&#x5217;&#xFF0C;&#x5728;<code>update</code>&#x4E2D;&#x8BED;&#x53E5;&#x6709;&#x6548;&#xFF0C;&#x6216;<code>save</code>&#x65B9;&#x6CD5;&#x5224;&#x65AD;&#x6807;&#x51C6;</li>
</ul>
<h4 id="insert">insert</h4>
<ul>
<li>&#x5165;&#x53C2;: <code>data</code> : <code>Map</code> <code>insert</code>&#x7684;&#x5217;&#x548C;&#x503C;&#xFF0C;&#x53EF;&#x7701;&#x7565;(&#x901A;&#x8FC7;<code>column</code>&#x8BBE;&#x7F6E;)</li>
</ul>
<pre><code class="lang-js"><span class="hljs-comment">// insert into sys_user(user_name,role) values(&apos;&#x674E;&#x5BCC;&#x8D35;&apos;,&apos;admin&apos;)</span>
<span class="hljs-keyword">return</span> db.table(<span class="hljs-string">&apos;sys_user&apos;</span>).insert({ user_name : <span class="hljs-string">&apos;&#x674E;&#x5BCC;&#x8D35;&apos;</span>, role : <span class="hljs-string">&apos;admin&apos;</span>})
</code></pre>
<h4 id="update">update</h4>
<ul>
<li>&#x5165;&#x53C2;: <code>data</code> : <code>Map</code> <code>insert</code>&#x7684;&#x5217;&#x548C;&#x503C;&#xFF0C;&#x53EF;&#x7701;&#x7565;(&#x901A;&#x8FC7;<code>column</code>&#x8BBE;&#x7F6E;)</li>
</ul>
<pre><code class="lang-javascript"><span class="hljs-comment">// update sys_user set user_name = &apos;&#x738B;&#x4E8C;&#x72D7;&apos; where id = 1</span>
<span class="hljs-keyword">return</span> db.table(<span class="hljs-string">&apos;sys_user&apos;</span>).primary(<span class="hljs-string">&apos;id&apos;</span>).update({ id: <span class="hljs-number">1</span>, user_name : <span class="hljs-string">&apos;&#x738B;&#x4E8C;&#x72D7;&apos;</span>})
</code></pre>
<h4 id="save">save</h4>
<ul>
<li>&#x5165;&#x53C2;: <code>data</code> : <code>Map</code> <code>insert</code>&#x6216;<code>update</code>&#x7684;&#x5217;&#x548C;&#x503C;&#xFF0C;&#x53EF;&#x7701;&#x7565;(&#x901A;&#x8FC7;<code>column</code>&#x8BBE;&#x7F6E;)</li>
<li>&#x5165;&#x53C2;&#xFF1A; <code>beforeQuery</code> &#xFF1A; <code>boolean</code> &#x662F;&#x5426;&#x6839;&#x636E;id&#x67E5;&#x8BE2;&#x6709;&#x6CA1;&#x6709;&#x6570;&#x636E;&#xFF0C;&#x53EF;&#x7701;&#x7565;(&#x9ED8;&#x8BA4;<code>false</code>)</li>
</ul>
<pre><code class="lang-javascript"><span class="hljs-comment">// insert into sys_user(id,user_name) values(&apos;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx&apos;,&apos;&#x738B;&#x4E8C;&#x72D7;&apos;);</span>
<span class="hljs-keyword">return</span> db.table(<span class="hljs-string">&apos;sys_user&apos;</span>).primary(<span class="hljs-string">&apos;id&apos;</span>, uuid()).save({user_name: <span class="hljs-string">&apos;&#x738B;&#x4E8C;&#x72D7;&apos;</span>});
<span class="hljs-comment">// insert into sys_user(user_name) values(&apos;&#x738B;&#x4E8C;&#x72D7;&apos;);</span>
<span class="hljs-keyword">return</span> db.table(<span class="hljs-string">&apos;sys_user&apos;</span>).primary(<span class="hljs-string">&apos;id&apos;</span>).save({user_name: <span class="hljs-string">&apos;&#x738B;&#x4E8C;&#x72D7;&apos;</span>});
<span class="hljs-comment">// update sys_user set user_name = &apos;&#x738B;&#x4E8C;&#x72D7;&apos; where id = 1</span>
<span class="hljs-keyword">return</span> db.table(<span class="hljs-string">&apos;sys_user&apos;</span>).primary(<span class="hljs-string">&apos;id&apos;</span>).save({id: <span class="hljs-number">1</span>,user_name: <span class="hljs-string">&apos;&#x738B;&#x4E8C;&#x72D7;&apos;</span>});
</code></pre>
<h4 id="select">select</h4>
<p>&#x67E5;&#x8BE2;list&#xFF08;&#x4E0E;db.select &#x4F5C;&#x7528;&#x76F8;&#x540C;&#xFF09;</p>
<pre><code class="lang-js"><span class="hljs-comment">// select * from sys_user</span>
<span class="hljs-keyword">return</span> db.table(<span class="hljs-string">&apos;sys_user&apos;</span>).select()
</code></pre>
<h4 id="where">where</h4>
<p>&#x8BBE;&#x7F6E;&#x67E5;&#x8BE2;&#x6761;&#x4EF6;</p>
<ul>
<li>eq --&gt; <code>==</code></li>
<li>ne --&gt; <code>&lt;&gt;</code></li>
<li>lt --&gt; <code>&lt;</code></li>
<li>gt --&gt; <code>&gt;</code></li>
<li>lte --&gt; <code>&lt;=</code></li>
<li>gte --&gt; <code>&gt;=</code></li>
<li>in --&gt; <code>in</code></li>
<li>notIn --&gt; <code>not in</code></li>
<li>like --&gt; <code>like</code></li>
<li>notLike --&gt; <code>not like</code></li>
</ul>
<pre><code class="lang-js"><span class="hljs-comment">// select * from sys_user where user_name like &apos;%&#x674E;&#x5BCC;&#x8D35;%&apos; and role = &apos;admin&apos;</span>
<span class="hljs-keyword">return</span> db.table(<span class="hljs-string">&apos;sys_user&apos;</span>)
    .where()
    .like(<span class="hljs-string">&apos;user_name&apos;</span>,<span class="hljs-string">&apos;%&#x674E;&#x5BCC;&#x8D35;%&apos;</span>)
    .eq(<span class="hljs-string">&apos;role&apos;</span>,<span class="hljs-string">&apos;admin&apos;</span>)
    .select()
</code></pre>
<h4 id="&#x5176;&#x5B83;">&#x5176;&#x5B83;</h4>
<p>&#x5176;&#x4ED6;API&#x53C2;&#x8003;mybatis-plus&#x5373;&#x53EF;&#x3002;</p>

                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="crud.html" class="navigation navigation-prev " aria-label="Previous page: 增删改查">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="page.html" class="navigation navigation-next " aria-label="Next page: 分页查询">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"单表操作","level":"1.2.3","depth":2,"next":{"title":"分页查询","level":"1.2.4","depth":2,"path":"start/page.md","ref":"start/page.md","articles":[]},"previous":{"title":"增删改查","level":"1.2.2","depth":2,"path":"start/crud.md","ref":"start/crud.md","articles":[]},"dir":"ltr"},"config":{"gitbook":"*","theme":"default","variables":{},"plugins":[],"pluginsConfig":{"highlight":{},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"}},"file":{"path":"start/table.md","mtime":"2023-12-28T06:32:40.630Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2024-01-02T08:17:25.965Z"},"basePath":"..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../gitbook/gitbook.js"></script>
    <script src="../gitbook/theme.js"></script>
    
        
        <script src="../gitbook/gitbook-plugin-search/search-engine.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search/search.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    </body>
</html>

